package com.spsy.order.listener;

import com.alibaba.nacos.shaded.com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.rabbitmq.client.Channel;
import com.spsy.order.api.OrderApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.util.concurrent.*;

/**
 *
 * 消费队列
 * @author: liuzhiping
 * @date: 2025/5/8 15:35
 **/
@Component
@RabbitListener(queues = "2209a_queue_a3")
@Slf4j
public class DirectListener {


    public static final ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("notice-order-pool-%d").build();
    public static final ExecutorService executorService = new ThreadPoolExecutor(5, 10, 0L,
            TimeUnit.MICROSECONDS, new LinkedBlockingQueue<Runnable>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());

    @RabbitHandler
    public void handlder(String str , Message message , Channel channel) throws Exception{
        log.info("order-----> 接受消息 str:{}", str);

        executorService.submit(()->{
            log.info("------->处理业务逻辑");
        });

        channel.basicAck(3,false);

         //接受消息
        // this.orderApi.notifyOrder(str);
        /* String payload = new String(message.getBody());
        System.out.println("Received message: " + payload);*/

    }
}
